package cn.wit.summit.chwan.ui.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.ui.base.MyActivity;
import cn.wit.summit.chwan.ui.fragment.MakeMoneyRankingFragment;
import cn.wit.summit.chwan.ui.fragment.MakeMoneyRankingIndexFragment;

/**
 * Created by Alan on 2018/8/31.
 */

public class MakeMoneyRankingIndexActivity extends MyActivity {

    private FragmentManager fragmentManager;
//    private MakeMoneyRankingIndexFragment rankingIndexFragment;
    private MakeMoneyRankingFragment rankingIndexFragment;
    private String makemoneyTwoTag = "makemoneytwo";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_make_money_ranking_index);
        ButterKnife.bind(this);

        setBarTitleTx(R.string.makemoney_ranking_title);

        fragmentManager = getSupportFragmentManager();
        if (savedInstanceState != null) {
//            rankingIndexFragment = (MakeMoneyRankingIndexFragment) fragmentManager.findFragmentByTag(makemoneyTwoTag);
            rankingIndexFragment = (MakeMoneyRankingFragment) fragmentManager.findFragmentByTag(makemoneyTwoTag);
        }
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        hideFragments(transaction);

        if (rankingIndexFragment == null) {
//            rankingIndexFragment = new MakeMoneyRankingIndexFragment();
            rankingIndexFragment = MakeMoneyRankingFragment.newInstance(1);
            transaction.add(R.id.makeMoneyMainFl, rankingIndexFragment, makemoneyTwoTag);
        } else {
            transaction.show(rankingIndexFragment);
        }

        try {
            transaction.commit();
        } catch (Exception e) {
        }
    }

    private void hideFragments(FragmentTransaction transaction) {
        if (rankingIndexFragment != null) {
            transaction.hide(rankingIndexFragment);
        }
    }

}
